﻿using AppFramework.Version.Dtos;
using AppFramework.Version;
using Abp.Application.Editions;
using Abp.Application.Features;
using Abp.Auditing;
using Abp.Authorization;
using Abp.Authorization.Users;
using Abp.DynamicEntityProperties;
using Abp.EntityHistory;
using Abp.Localization;
using Abp.Notifications;
using Abp.Organizations;
using Abp.UI.Inputs;
using Abp.Webhooks;
using AutoMapper;
using IdentityServer4.Extensions;
using AppFramework.Auditing.Dto;
using AppFramework.Authorization.Accounts.Dto;
using AppFramework.Authorization.Delegation;
using AppFramework.Authorization.Permissions.Dto;
using AppFramework.Authorization.Roles;
using AppFramework.Authorization.Roles.Dto;
using AppFramework.Authorization.Users;
using AppFramework.Authorization.Users.Delegation.Dto;
using AppFramework.Authorization.Users.Dto;
using AppFramework.Authorization.Users.Importing.Dto;
using AppFramework.Authorization.Users.Profile.Dto;
using AppFramework.Chat;
using AppFramework.Chat.Dto;
using AppFramework.DynamicEntityProperties.Dto;
using AppFramework.Editions;
using AppFramework.Editions.Dto;
using AppFramework.Friendships;
using AppFramework.Friendships.Cache;
using AppFramework.Friendships.Dto;
using AppFramework.Localization.Dto;
using AppFramework.MultiTenancy;
using AppFramework.MultiTenancy.Dto;
using AppFramework.MultiTenancy.HostDashboard.Dto;
using AppFramework.MultiTenancy.Payments;
using AppFramework.MultiTenancy.Payments.Dto;
using AppFramework.Notifications.Dto;
using AppFramework.Organizations.Dto;
using AppFramework.Sessions.Dto;
using AppFramework.WebHooks.Dto;
using AppFramework.Demo.Dtos;
using AppFramework.Demo;
using AppFramework.DinosaursParkMes.Process;
using AppFramework.DinosaursParkMes.Process.DTO;
using AppFramework.DinosaursParkMes.Dictionaries.Dto;
using AppFramework.DinosaursParkMes.DictionariesModel;
using AppFramework.DinosaursParkMes.BOM;
using AppFramework.DinosaursParkMes.BOM.Dto;
using AppFramework.DinosaursParkMes.CodingRuleModel;
using AppFramework.DinosaursParkMes.WorkOrder.Dto;
using System.Collections.Generic;
using AppFramework.DinosaursParkMes.Product.DTO;
using AppFramework.DinosaursParkMes.Product;
using AppFramework.DinosaursParkMes.Material.Dto;
using AppFramework.DinosaursParkMes.MaterialModel;
using AppFramework.DinosaursParkMes.Production;
using AppFramework.DinosaursParkMes.Production.DTO;
using AppFramework.DinosaursParkMes.ProductionPlanning.Dto;
using AppFramework.DinosaursParkMes.ProductionPlanningModel;
using AppFramework.DinosaursParkMes.TicketTask.DTO;
using AppFramework.DinosaursParkMes.TicketTask;
using AppFramework.DinosaursParkMes.ProductWork.Dto;
using AppFramework.DinosaursParkMes.ProductionReturn.DTO;
using AppFramework.DinosaursParkMes.ProductionReturn;
using AppFramework.DinosaursParkMes.UniqueIdCode.Dto;
using AppFramework.DinosaursParkMes.Execute.Dto;
using AppFramework.DinosaursParkMes.SignalR.DTo;
using AppFramework.DinosaursParkMes.SingnalrModel;

namespace AppFramework
{
    internal static class CustomDtoMapper
    {
        public static void CreateMappings(IMapperConfigurationExpression configuration)
        {
            //赋码管理
            configuration.CreateMap<UniqueIdCodeAddDTO, DinosaursParkMes.MaterialModel.UniqueIdCode>();
            configuration.CreateMap<DinosaursParkMes.MaterialModel.UniqueIdCode,ShowUniqueIdCodeDto > ();
            //生产退料管理
            configuration.CreateMap<ProductionReturnRequestDTO, ProductionReturninfo>();
            configuration.CreateMap<ProductionReturnItem, ReturnofMaterialinfo>();
            //生产计划
            configuration.CreateMap<AddProductionPlanningDto, ProductionPlanning>().ReverseMap();
            configuration.CreateMap<ProductionPlanningAccessorylist, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<ProductionPlanning, ShowProductionPlanningDto>().ReverseMap();
            configuration.CreateMap<DetailsProductionPlanningDTO, ProductionPlanning>().ReverseMap();
            configuration.CreateMap<ProductionPlanningAccessory, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<DetailsProductionPlanningDTO, ProductionPlanning>().ReverseMap();
            configuration.CreateMap<ProductionPlanningAccessory, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<MaterialProductMessage, Material>().ReverseMap();
            configuration.CreateMap<MaterialProductMessage, Productinfo>().ReverseMap();
            configuration.CreateMap<MaterialMessage, Material>().ReverseMap();
            configuration.CreateMap<ProductMessage, Productinfo>().ReverseMap();
            configuration.CreateMap<WorkOrderMessage, ProductWorkModels>().ReverseMap();
            //工单任务
            configuration.CreateMap<SendWorkRequestDTO,SendWorkinfo>();
            configuration.CreateMap<TicketTaskinfoResponseDTO, TicketTaskinfo>().ReverseMap();
            configuration.CreateMap<ProductWorkModels, ProductWorkExcelDto>().ReverseMap();
            configuration.CreateMap<Material, WuLiaoItem>();
            configuration.CreateMap<WuLiaoItem, Material>();
            configuration.CreateMap<TicketTaskinfo, TicketTaskSelectResponseDTO>();
            configuration.CreateMap<TicketTaskinfoResponseDTO, TicketTaskOutPutDTO>();
            //物料
            configuration.CreateMap<AddMaterialDTO, Material>().ReverseMap();
            configuration.CreateMap<ImgList, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<Accessorylist, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<Material, MaterialParticulars>();
            configuration.CreateMap<MaterialProductImg, ParticularsImgList>();
            configuration.CreateMap<MaterialProductImg, ParticularsAccessorylist>();
            configuration.CreateMap<Material, MaterialExcelDto>();
            //Product
            configuration.CreateMap<ProductRequestDTO, Productinfo>();
            configuration.CreateMap<Productinfo, ProductSelectDTO>().ReverseMap();
            configuration.CreateMap<ProductImageItem, MaterialProductImg>().ReverseMap();
            configuration.CreateMap<AccessoryItem, MaterialProductImg>().ReverseMap();

            ///数据字典
            configuration.CreateMap<AddDictionariesDto, Dictionaries>().ReverseMap();
            configuration.CreateMap<DictionarieslistItemDto, Dictionarieslist>().ReverseMap();
            configuration.CreateMap<DictionarieslistDto, Dictionarieslist>().ReverseMap();
            //Codingrule
            configuration.CreateMap<RequestCodingDTO, Codingrules>();
            configuration.CreateMap<Codingrules, ResponseCodingruleDTO>();
            configuration.CreateMap<Codingrules, CodingruleDTO>();
            //工单
            configuration.CreateMap<ProductWorkModels, ProductWorkDto>().ReverseMap();
            configuration.CreateMap<ProductWorkModels, FindProduct>().ReverseMap();
            configuration.CreateMap<BillOfMaterialDetails, ProductBillOfMaterialDto>().ReverseMap();
            configuration.CreateMap<CraftProcessModel, PRoductProcessInfoDto>().ReverseMap();
            configuration.CreateMap<TicketTaskinfo, TicketInsertDto>().ReverseMap();
            configuration.CreateMap<ProductWorkModels, ExecuteDto>().ReverseMap();
            //BOM
            configuration.CreateMap<BillOfMaterialDto, BillOfMaterial>().ReverseMap();
            configuration.CreateMap<BOMDataOutDTO, BillOfMaterial>().ReverseMap();
            //Process
            configuration.CreateMap<CraftProcessDto2, CraftProcessModel>();
            configuration.CreateMap<CraftRouteModel, CraftRouteAddDTO>();
            configuration.CreateMap<CraftRouteAddDTO, CraftRouteModel>();
            configuration.CreateMap<ProcessModel, ProcessAdd>();
            configuration.CreateMap<ProcessAdd, ProcessModel>();
            configuration.CreateMap<CraftProcessModel, CraftProcessDTO>();
            configuration.CreateMap<CraftProcessDTO, CraftProcessModel>();
            configuration.CreateMap<BillOfMaterialDetailDto,BillOfMaterialDetails>().ReverseMap();

            //Material
            configuration.CreateMap<MaterialRequisitionDTO, MaterialRequisition>();
            configuration.CreateMap<MaterialRequisition, MaterialRequisitionDTO>();
            configuration.CreateMap<MaterialBOMDTO, MaterialRequisitionBOM>();
            configuration.CreateMap<MaterialRequisitionBOM, MaterialBOMDTO>();

            //通知
            configuration.CreateMap<Announcement, ResponseAnnounDTO>().ReverseMap();


            #region 系统基础
            configuration.CreateMap<AbpDemoDto, AbpDemo>().ReverseMap();

            configuration.CreateMap<CreateOrEditAbpVersionDto, AbpVersion>().ReverseMap();
            configuration.CreateMap<AbpVersionDto, AbpVersion>().ReverseMap();
            //Inputs
            configuration.CreateMap<CheckboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<SingleLineStringInputType, FeatureInputTypeDto>();
            configuration.CreateMap<ComboboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<IInputType, FeatureInputTypeDto>()
                .Include<CheckboxInputType, FeatureInputTypeDto>()
                .Include<SingleLineStringInputType, FeatureInputTypeDto>()
                .Include<ComboboxInputType, FeatureInputTypeDto>();
            configuration.CreateMap<StaticLocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>();
            configuration.CreateMap<ILocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>()
                .Include<StaticLocalizableComboboxItemSource, LocalizableComboboxItemSourceDto>();
            configuration.CreateMap<LocalizableComboboxItem, LocalizableComboboxItemDto>();
            configuration.CreateMap<ILocalizableComboboxItem, LocalizableComboboxItemDto>()
                .Include<LocalizableComboboxItem, LocalizableComboboxItemDto>();

            //Chat
            configuration.CreateMap<ChatMessage, ChatMessageDto>();
            configuration.CreateMap<ChatMessage, ChatMessageExportDto>();

            //Feature
            configuration.CreateMap<FlatFeatureSelectDto, Feature>().ReverseMap();
            configuration.CreateMap<Feature, FlatFeatureDto>();

            //Role
            configuration.CreateMap<RoleEditDto, Role>().ReverseMap();
            configuration.CreateMap<Role, RoleListDto>();
            configuration.CreateMap<UserRole, UserListRoleDto>();

            //Edition
            configuration.CreateMap<EditionEditDto, SubscribableEdition>().ReverseMap();
            configuration.CreateMap<EditionCreateDto, SubscribableEdition>();
            configuration.CreateMap<EditionSelectDto, SubscribableEdition>().ReverseMap();
            configuration.CreateMap<SubscribableEdition, EditionInfoDto>();

            configuration.CreateMap<Edition, EditionInfoDto>().Include<SubscribableEdition, EditionInfoDto>();

            configuration.CreateMap<SubscribableEdition, EditionListDto>();
            configuration.CreateMap<Edition, EditionEditDto>();
            configuration.CreateMap<Edition, SubscribableEdition>();
            configuration.CreateMap<Edition, EditionSelectDto>();

            //Payment
            configuration.CreateMap<SubscriptionPaymentDto, SubscriptionPayment>().ReverseMap();
            configuration.CreateMap<SubscriptionPaymentListDto, SubscriptionPayment>().ReverseMap();
            configuration.CreateMap<SubscriptionPayment, SubscriptionPaymentInfoDto>();

            //Permission
            configuration.CreateMap<Permission, FlatPermissionDto>();
            configuration.CreateMap<Permission, FlatPermissionWithLevelDto>();

            //Language
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageEditDto>();
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageListDto>();
            configuration.CreateMap<NotificationDefinition, NotificationSubscriptionWithDisplayNameDto>();
            configuration.CreateMap<ApplicationLanguage, ApplicationLanguageEditDto>()
                .ForMember(ldto => ldto.IsEnabled, options => options.MapFrom(l => !l.IsDisabled));

            //Tenant
            configuration.CreateMap<Tenant, RecentTenant>();
            configuration.CreateMap<Tenant, TenantLoginInfoDto>();
            configuration.CreateMap<Tenant, TenantListDto>();
            configuration.CreateMap<TenantEditDto, Tenant>().ReverseMap();
            configuration.CreateMap<CurrentTenantInfoDto, Tenant>().ReverseMap();

            //User
            configuration.CreateMap<User, UserEditDto>()
                .ForMember(dto => dto.Password, options => options.Ignore())
                .ReverseMap()
                .ForMember(user => user.Password, options => options.Ignore());
            configuration.CreateMap<User, UserLoginInfoDto>();
            configuration.CreateMap<User, UserListDto>();
            configuration.CreateMap<User, ChatUserDto>();
            configuration.CreateMap<User, OrganizationUnitUserListDto>();
            configuration.CreateMap<Role, OrganizationUnitRoleListDto>();
            configuration.CreateMap<CurrentUserProfileEditDto, User>().ReverseMap();
            configuration.CreateMap<UserLoginAttemptDto, UserLoginAttempt>().ReverseMap();
            configuration.CreateMap<ImportUserDto, User>();

            //AuditLog
            configuration.CreateMap<AuditLog, AuditLogListDto>();
            configuration.CreateMap<EntityChange, EntityChangeListDto>();
            configuration.CreateMap<EntityPropertyChange, EntityPropertyChangeDto>();

            //Friendship
            configuration.CreateMap<Friendship, FriendDto>();
            configuration.CreateMap<FriendCacheItem, FriendDto>();

            //OrganizationUnit
            configuration.CreateMap<OrganizationUnit, OrganizationUnitDto>();

            //Webhooks
            configuration.CreateMap<WebhookSubscription, GetAllSubscriptionsOutput>();
            configuration.CreateMap<WebhookSendAttempt, GetAllSendAttemptsOutput>()
                .ForMember(webhookSendAttemptListDto => webhookSendAttemptListDto.WebhookName,
                    options => options.MapFrom(l => l.WebhookEvent.WebhookName))
                .ForMember(webhookSendAttemptListDto => webhookSendAttemptListDto.Data,
                    options => options.MapFrom(l => l.WebhookEvent.Data));

            configuration.CreateMap<WebhookSendAttempt, GetAllSendAttemptsOfWebhookEventOutput>();

            configuration.CreateMap<DynamicProperty, DynamicPropertyDto>().ReverseMap();
            configuration.CreateMap<DynamicPropertyValue, DynamicPropertyValueDto>().ReverseMap();
            configuration.CreateMap<DynamicEntityProperty, DynamicEntityPropertyDto>()
                .ForMember(dto => dto.DynamicPropertyName,
                    options => options.MapFrom(entity => entity.DynamicProperty.DisplayName.IsNullOrEmpty() ? entity.DynamicProperty.PropertyName : entity.DynamicProperty.DisplayName));
            configuration.CreateMap<DynamicEntityPropertyDto, DynamicEntityProperty>();

            configuration.CreateMap<DynamicEntityPropertyValue, DynamicEntityPropertyValueDto>().ReverseMap();

            //User Delegations
            configuration.CreateMap<CreateUserDelegationDto, UserDelegation>();

            /* ADD YOUR OWN CUSTOM AUTOMAPPER MAPPINGS HERE */
            #endregion

        }
    }
}